//
//  YHMainBarVC.swift
//  XLWB
//
//  Created by key on 16/6/25.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class YHMainBarVC: UITabBarController {

    override func loadView() {
        super.loadView()
        view.backgroundColor = UIColor.whiteColor()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = YHBar()
        
        //KVC 强行设置自定义标签栏
        setValue(tabBar, forKey: "tabBar")
        
        //实现闭包 跳转界面
        tabBar.closBag = {() -> () in
            
            let nav = UINavigationController(rootViewController: YHComposeVC())
            
            self.presentViewController(nav, animated: true, completion: nil)
            
            
        }
        
        
        //加载子控制器
        addChildViewController(YHHomeVC(), title: "首页", img: "tabbar_home")
        addChildViewController(YHMessageVC(), title: "消息", img: "tabbar_discover")
        addChildViewController(YHFoundVC(), title: "发现", img: "tabbar_message_center")
        addChildViewController(YHMeVC(), title: "我", img: "tabbar_profile")
        
        
        tabBar.tintColor = themeColor
    }
    
    //MARK: - 加载子控制器
    func addChildViewController(vc : UIViewController, title : String, img : String) {
        
        let vcc = YHMainNavVC(rootViewController:vc)
        
        vcc.title = title
        
        vcc.tabBarItem.image = UIImage(named: img)
        
        vcc.tabBarItem.selectedImage = UIImage(named: "\(img)_selected")
        
        addChildViewController(vcc)
        
    }
    
    
    

}
